package com.atguigu.spzx.manager.mapper;

import com.atguigu.spzx.manager.entity.SysMenu;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 菜单表 Mapper 接口
 * </p>
 *
 * @author flyduck
 * @since 2023-10-25
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    /**
     * 根据用户id查询菜单
     *
     * @param userId
     * @return
     */
    List<SysMenu> getMenuListByUserId(@Param("userId") Long userId);


    /**
     * 根据parentId查询
     * @param parentId
     * @return
     */
    default List<SysMenu> getMenuListByParentId(Long parentId) {
        QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", parentId);
        return this.selectList(queryWrapper);
    }

    /**
     * 根据parentId查询
     * @param parentId
     * @return
     */
    default Integer getMenuCountByParentId(Long parentId) {
        QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", parentId);
        return this.selectCount(queryWrapper);
    }


    /**
     * 根据状态查询
     * @param status
     * @return
     */
    default List<SysMenu> getMenuListByStatus(int status) {
        QueryWrapper<SysMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", status);
        queryWrapper.orderByAsc("sort_value");
        return this.selectList(queryWrapper);
    }



}

